﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Windows.Media; 

namespace MapTool
{


    public static class DistinctColorGenerator
    {
        public static List<Color> GenerateDistinctColors(int count)
        {
            var colors = new List<Color>();
            const double saturation = 0.8; // 饱和度 (0-1)
            const double lightness = 0.6;  // 亮度 (0-1)

            // 黄金角分布算法 (137.5度)
            const double goldenAngle = 137.5;

            for (int i = 0; i < count; i++)
            {
                // 均匀分布色相 (0-360度)
                double hue = (i * goldenAngle) % 360;

                // 转换为 RGB
                var color = HslToRgb(hue, saturation, lightness);
                colors.Add(color);
            }

            return colors;
        }

        private static Color HslToRgb(double h, double s, double l)
        {
            double r, g, b;

            // 将色相归一化到 0-360
            h %= 360;
            if (h < 0) h += 360;

            // HSL 转 RGB 算法
            double c = (1 - Math.Abs(2 * l - 1)) * s;
            double x = c * (1 - Math.Abs((h / 60) % 2 - 1));
            double m = l - c / 2;

            if (h < 60)
            {
                r = c; g = x; b = 0;
            }
            else if (h < 120)
            {
                r = x; g = c; b = 0;
            }
            else if (h < 180)
            {
                r = 0; g = c; b = x;
            }
            else if (h < 240)
            {
                r = 0; g = x; b = c;
            }
            else if (h < 300)
            {
                r = x; g = 0; b = c;
            }
            else
            {
                r = c; g = 0; b = x;
            }

            return Color.FromRgb(
                (byte)((r + m) * 255),
                (byte)((g + m) * 255),
                (byte)((b + m) * 255)
            );
        }
    }
}
